package com.briup.exception;/*
 * @Description:
 * @Author: 枸男人
 * @Date: 2024/12/04/11:34
 * @LastEditors: 34866
 * @: 你说哥帅,哥笑了,因为哥笑起来更帅
 */

import com.briup.utils.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
 * 全局异常处理
 */
//@ControllerAdvice + @ResponseBody
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        Result result = null;
        if (e instanceof ServiceException) {
            result = Result.failure(((ServiceException) e).getResultCode());
        } else {
            result = Result.failure(500, "服务器意外错误：" + e.getMessage());
        }
        return result;
    }
}
